<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增【请填写功能名称】')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-expense-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">报销类型：</label>
            <div class="col-sm-8">
                <div class="col-sm-8">
                    <select id="eType" name="eType" th:with="type=${@dict.getType('expense_eType')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">报销原因：</label>
            <div class="col-sm-8">
                <input id="eReason" name="eReason" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">报销申请时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input id="eTimeStart" name="eTimeStart" class="form-control" placeholder="yyyy-MM-dd" type="text">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">报销金额：</label>
            <div class="col-sm-8">
                <input id="eMoney" name="eMoney" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">申请人：</label>
            <div class="col-sm-8">
                <input id="eTheHeir" name="eTheHeir" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">创建人：</label>
            <div class="col-sm-8">
                <input id="eCreator" name="eCreator" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">申请人部门：</label>
            <div class="col-sm-8">
                <input id="eDepa" name="eDepa" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">申请人头像：</label>
            <div class="col-sm-8">
                <input id="ePicture" name="ePicture" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文件上传凭证：</label>
            <div class="col-sm-8">
                <input id="eRemark" name="eRemark" class="form-control" type="file">
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">报销状态：</label>
            <div class="col-sm-8">
                <div class="radio-box">
                    <div class="radio-box">
                        <select id="eStatus" name="eStatus" th:with="type=${@dict.getType('exa_expense_stutas')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">审批意见：</label>
            <div class="col-sm-8">
                <input id="eOpinion" name="eOpinion" class="form-control" type="text">
            </div>
        </div>

    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script type="text/javascript">
    var prefix = ctx + "ruoyi/expense"
    $("#form-expense-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            uploadFile();
        }
    }

    function uploadFile() {
        var formData = new FormData();
        if ($('#eRemark')[0].files[0] == null) {
            $.modal.alertWarning("请先选择文件路径");
            return false;
        }
        formData.append('eType', $("#eType").val());
        formData.append('eReason', $("#eReason").val());
        formData.append('eTimeStart', $("#eTimeStart").val());
        formData.append('eMoney', $("#eMoney").val());
        formData.append('eTheHeir', $("#eTheHeir").val());
        formData.append('eCreator', $("#eCreator").val());
        formData.append('eDepa', $("#eDepa").val());
        formData.append('ePicture', $("#ePicture").val());
        formData.append('eStatus', $("#eStatus").val());
        formData.append('eOpinion', $("#eOpinion").val());
        formData.append('file', $('#eRemark')[0].files[0]);
        $.ajax({
            url: prefix + "/add/",
            type: 'post',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success: function(result) {
                $.operate.successCallback(result);
            }
        });
    }

    $("input[name='eTimeStart']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
</script>
</body>
</html>